﻿
using Mono.Cecil;

public abstract class LuaMemberReference : LuaVarReference
{
    public MemberReference Self { get; }
    public override string Name { get; protected set; }
    public virtual string FullName { get; protected set; }
    public LuaMemberReference(LuaModuleDefinition module, MemberReference self) : base(module)
    {
        Self = self;
        var name = self.Name;
        /*var lastIndex = name.LastIndexOf('.');
        if (lastIndex > 0)
            name = self.Name.Substring(lastIndex + 1);*/
        Name = ToName(name);
        FullName = ToFullName(self.FullName);
    }
    public override string ToString()
    {
        return $"{Self.FullName}";
    }
}
public class LuaMemberReference<T> : LuaMemberReference where T : MemberReference
{
    private readonly T _self;

    public override ObjectKind StackType { get; }

    public T Resolve() => _self;
    public virtual T2 Resolve<T2>() where T2 : T
    {
        return _self as T2;
    }
    public LuaMemberReference(LuaModuleDefinition module, T self)
        : base(module, self)
    {
        _self = self;
        StackType = self.DeclaringType.ToStackType();
    }
}